package com.itheima.service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.Utils.MyBatisUtils;
import com.itheima.bean.Student;
import com.itheima.mapper.StudentMapper;
import org.apache.ibatis.session.SqlSession;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;


public class StudentService {
    public List<Student> selectByPage(String currentPage, String pageSize) {
        SqlSession sqlSession = MyBatisUtils.getSqlSession();
        StudentMapper stuMapper = sqlSession.getMapper(StudentMapper.class);
         Page es=null;
        if (currentPage!=null&&pageSize!=null){
           es = PageHelper.startPage(Integer.parseInt(currentPage), Integer.parseInt(pageSize));
        }

        List<Student> students = stuMapper.selectByPage();
        return students;
    }

    public void addStu(Student student) {
        SqlSession sqlSession = MyBatisUtils.getSqlSession();
        StudentMapper mapper = sqlSession.getMapper(StudentMapper.class);
        mapper.addStu(student);
    }

    public void update(Student student) {
        SqlSession sqlSession = MyBatisUtils.getSqlSession();
        StudentMapper mapper = sqlSession.getMapper(StudentMapper.class);
        mapper.update(student);

    }


    public void deleteStu(String number) {
        SqlSession sqlSession = MyBatisUtils.getSqlSession();
        StudentMapper mapper = sqlSession.getMapper(StudentMapper.class);
        mapper.deleteStu(number);
    }
}
